package cn.lystudio.rohmtimeopwide_background_v11.controller.appApi;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.collection.CollUtil;
import cn.lystudio.rohmtimeopwide_background_v11.entity.po.PartPO;
import cn.lystudio.rohmtimeopwide_background_v11.service.PartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app-api/part")
@CrossOrigin
@SaIgnore
@Slf4j
public class AppPartController {
    private PartService partService;
    @Lazy
    @Autowired
    public void setPartService(PartService partService) {
        this.partService = partService;
    }

    @GetMapping("/getPartByMachineNo")
    public SaResult getPartByMachineNo(@RequestParam("machineNo")String machineNo){
        List<PartPO> partList = partService.getListByMachineNo(machineNo);
        if(CollUtil.isEmpty(partList)) return SaResult.error("设备部位无数据");
        return SaResult.data(partList);
    }
}
